package com.askinhand.service.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.askinhand.bean.AudioAnswer;
import com.askinhand.bean.AudioQues;
import com.askinhand.bean.PictureAnswer;
import com.askinhand.dao.impl.AudioAnswerDAO;
import com.askinhand.dao.impl.AudioQuesDAO;
import com.askinhand.service.IAudioAnswerService;

public class AudioAnswerService implements IAudioAnswerService{
	
	AudioQuesDAO audioquesDAO;
	AudioAnswerDAO audioAnswerDAO;
	
	public AudioQuesDAO getAudioquesDAO() {
		return audioquesDAO;
	}

	public void setAudioquesDAO(AudioQuesDAO audioquesDAO) {
		this.audioquesDAO = audioquesDAO;
	}

	public AudioAnswerDAO getAudioAnswerDAO() {
		return audioAnswerDAO;
	}

	public void setAudioAnswerDAO(AudioAnswerDAO audioAnswerDAO) {
		this.audioAnswerDAO = audioAnswerDAO;
	}

	public List findAudioAnswer() {
		// TODO Auto-generated method stub
		return audioAnswerDAO.findAll();
	}

	public void save(AudioAnswer aa) {
		// TODO Auto-generated method stub
		audioAnswerDAO.save(aa);
	}
	
	public ArrayList personalAnswerReturn(String uid) {
		// TODO Auto-generated method stub
		ArrayList<AudioAnswer> audio=new ArrayList<AudioAnswer>();

		List li=audioAnswerDAO.findByUid(Integer.parseInt(uid));
		Iterator it=li.iterator();
		while(it.hasNext()){
			AudioAnswer audioanswer=(AudioAnswer)it.next();
			audio.add(audioanswer);
			}
		
		
		
		return audio;
	}

	public String answerSubmit(String content, String qid) {
		// TODO Auto-generated method stub
		
		AudioQues audioques=audioquesDAO.findById(Integer.parseInt(qid));
		int uid=audioques.getUid();
		AudioAnswer audioanswer=new AudioAnswer();
		audioanswer.setContent(content);
		audioanswer.setQid(Integer.parseInt(qid));
		audioanswer.setUid(uid);
			
		audioAnswerDAO.save(audioanswer);
			
		return "success";
	}

	public String rate(String answerid, String isGood, String feedback) {
		// TODO Auto-generated method stub
		AudioAnswer audioanswer=audioAnswerDAO.findById(Integer.parseInt(answerid));
		audioanswer.setFeedback(feedback);
		audioanswer.setIsGood(isGood);
		audioAnswerDAO.update(audioanswer);

		return "success";
	}

}
